<template>
    <view class="content">
        <view class="nav">
            <view class="nav-i" :class="{active : type == 0}" @click="chooseNav(0)">全部</view>
            <view class="nav-i" :class="{active : type == 1}" @click="chooseNav(1)">待支付</view>
            <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">待发货</view>
            <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">待收货</view>
            <view class="nav-i" :class="{active : type == 4}" @click="chooseNav(4)">已完成</view>
            <view class="nav-i" :class="{active : type == 8}" @click="chooseNav(8)">售后</view>
        </view>
        
        <view class="item" v-for="(item, index) in list" :key="index" @click="toDetail(item)">
            <view class="i-top" v-for="(el, ind) in item.goods_list" :key="ind" v-if="ind < 1">
                <image :src="el.image_uri" mode="aspectFit" class="img"></image>
                <view class="item-r">
                    <view class="goods-name">{{el.goods_name}}</view>
                    <!-- <view class="spec">12公斤大容量12公斤大容量12公斤大容量12公斤大容量</view> -->
                    <view class="item-d">
                        <view class="price">￥<text class="price-num">{{el.sale_price}}</text></view>
                        <!-- <view class="deposit">订金￥26.00</view> -->
                        <view class="num">x{{el.goods_nums}}</view>
                    </view>
                </view>
            </view>
            <view class="down">
                <view class="stu">{{item.order_status_txt}}</view>
                <view>
                    <text class="u-font-24">共{{item.goods_sum}}件商品 实付款：</text>
                    <text class="t-p">￥</text>
                    <text class="t-p-num">{{item.pay_amount}}</text>
                </view>
            </view>
            <!-- order_status_id
                0 => '待确认', 1 => '订单已确认', 2 => '订单已取消', 3 => '订单已关闭', 4 => '待付款', 5 => '待发货', 6 => '已发货', 
                7 => '申请退货', 8 => '退货中', 9 => '已退货', 10 => '申请退款', 11 => '退款中',12 => '拒绝退款', 13 => '已退款', 
                14 => '已收货', 15 => '已完成', 16 => '已退款', 17 => '部分退款/退货', 18 => '待收货', 19 => '已送达'
            -->
            <view class="btns" v-if="item.order_status_id == 4 || item.order_status_id == 5 || item.order_status_id == 6">
                <view class="btn1" v-if="item.order_status_id == 4" @click.stop="doCancel(item)">取消订单</view>
                <view class="btn2" v-if="item.order_status_id == 4" @click.stop="toPay(item)">立即付款</view>
                <view class="btn1" v-if="item.order_status_id == 5" @click.stop="toAfter(item)">申请退款</view>
                <view class="btn3" v-if="item.order_status_id == 6" @click.stop="doConfirm(item)">确认收货</view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                type: 0,
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
            };
        },
        onLoad(option) {
            this.type = option.type
        },
        onShow() {
            this.list = []
            this.page = 1
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            // order_status_id
            //     0 => '待确认', 1 => '订单已确认', 2 => '订单已取消', 3 => '订单已关闭', 4 => '待付款', 5 => '待发货', 6 => '已发货', 
            //     7 => '申请退货', 8 => '退货中', 9 => '已退货', 10 => '申请退款', 11 => '退款中',12 => '拒绝退款', 13 => '已退款', 
            //     14 => '已收货', 15 => '已完成', 16 => '已退款', 17 => '部分退款/退货', 18 => '待收货', 19 => '已送达'
            toDetail(item) {
                this.$gTo(`/pages/order/details?id=${item.id}&ost=${item.order_status_id}&type=${this.type}`)
            },
            
            doCancel(item) {
                this.$confirm('确认取消订单吗？',()=>{
                    this.$ajax('cancelOrder', {
                        userToken: this.$getSync('userToken'),
                        id: item.id,
                    }).then(ret => {
                    	if (ret.status == 0) {
                            this.$toast('取消成功');
                            setTimeout(() => {
                                this.list = []
                                this.page = 1
                                this.status = 'loadmore'
                                this.getList()
                            }, 500)
                    	} else {
                    		this.$toast(ret.message);
                    	}
                    });
                })
            },
            
            doConfirm(item) {
                this.$confirm('确认收货吗？',()=>{
                    this.$ajax('confirmGoods', {
                        userToken: this.$getSync('userToken'),
                        id: item.id,
                    }).then(ret => {
                    	if (ret.status == 0) {
                            this.$toast('确认收货成功');
                            setTimeout(() => {
                                this.list = []
                                this.page = 1
                                this.status = 'loadmore'
                                this.getList()
                            }, 500)
                    	} else {
                    		this.$toast(ret.message);
                    	}
                    });
                })
            },
            
            toAfter(item) {
                this.$gTo(`/pages/order/after?id=${item.id}`)
            },
            
            toPay(item) {
                this.$gTo('/pages/pay/pay?id=' + item.order_no + '&money=' + item.pay_amount)
            },
            
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.list = []
                this.page = 1
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('orderList', {
                    userToken: this.$getSync('userToken'),
                    page: this.page,
                    limit: 10,
                    tabIndex: this.type,//订单状态 0-全部 1-待付款 2-待发货 3-待收货 4-已完成并已评价 5-未完成配送单 6-已完成配送单 7-未评论 8-退款退货 9待成团
                }).then(ret => {
            		if (ret.status == 0) {
                        if (ret.data.length > 0) {
                        	this.list = this.list.concat(ret.data);
                        	this.page++;
                        	this.status = 'loadmore'
                        } else {
                        	this.status = 'nomore'
                        }
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    
    
    
    page{
        background-color: #f6f6f6;
    }
    .content{
        padding-bottom: 50rpx;
    }
    .nav{
        border-top: 2rpx solid #ebebeb;
        background-color: #fff;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .nav-i{
        width: calc(100vw / 6);
        padding: 30rpx 0;
        font-size: 28rpx;
        text-align: center;
    }
    .active{
        font-size: 32rpx;
        font-weight: bold;
        color: #00734c;
        border-bottom: 2rpx solid #00734c;
    }
    
    .item{
        padding: 0 20rpx;
        background-color: #fff;
        margin-top: 20rpx;
    }
    .i-top{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20rpx 0;
    }
    .img{
        width: 160rpx;
        height: 160rpx;
        border: 2rpx solid #e3e3e3;
        border-radius: 15rpx;
        overflow: hidden;
        margin-right: 25rpx;
    }
    .item-r{
        flex: 1;
    }
    .goods-name{
        width: 520rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 28rpx;
        font-weight: bold;
    }
    .spec{
        width: 520rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 24rpx;
        color: #6d6d6d;
        padding-top: 5rpx;
    }
    .item-d{
        padding-top: 45rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .price{
        font-size: 26rpx;
    }
    .price-num{
        font-size: 38rpx;
        font-weight: bold;
        padding-right: 30rpx;
    }
    .deposit{
        font-size: 24rpx;
        color: #ff5f2b;
        padding: 4rpx 12rpx;
        background-color: #fff1ec;
        border-radius: 5rpx;
    }
    .num{
        flex: 1;
        font-size: 26rpx;
        color: #929292;
        text-align: right;
    }
    
    .down{
        padding-bottom: 25rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .stu{
        font-size: 24rpx;
        color: #f62a2a;
    }
    .t-p{
        font-size: 24rpx;
        color: #f62a2a;
    }
    .t-p-num{
        font-size: 38rpx;
        color: #f62a2a;
    }
    .btns{
        padding-bottom: 20rpx;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .btn1{
        padding: 12rpx 20rpx;
        border: 2rpx solid #000;
        border-radius: 50rpx;
        box-sizing: border-box;
        margin-left: 20rpx;
    }
    .btn2{
        padding: 12rpx 20rpx;
        background-color: #00734c;
        border-radius: 50rpx;
        box-sizing: border-box;
        margin-left: 20rpx;
        color: #fff;
    }
    .btn3{
        padding: 12rpx 20rpx;
        background-color: #ff8a00;
        border-radius: 50rpx;
        box-sizing: border-box;
        margin-left: 20rpx;
        color: #fff;
    }

</style>
